var api = require('../../utils/api.js');
var app = getApp();


Page({

    /**
     * 页面的初始数据
     */
    data: {
        xieyi:0,
        show:false,
        info:{},
        sub:1,
        lists:[]
    },

    submits(){
        var xieyi=this.data.xieyi;
        var that=this;
        if  (!xieyi){
            wx.showToast({
              title: '请阅读并同意协议',
              icon:'none'
            })

            return false;
        }

        var  sub=this.data.sub;

        if(sub!=1){
            return false;
        }

        var info=this.data.info;

        api.post({
            url: 'server/submits',
            data: info,
            success: data => {
                if  (data.code==0){
                    wx.showToast({
                      title: data.msg,
                      icon:'none'
                    })
                }else{
                    wx.showToast({
                        title: data.msg,
                        icon:'none'
                      })

                      that.setData({
                        xieyi:0,
                        show:false,
                        info:{}
                      })
                      that.getmydown();
                }
            }
        })
    },

    getmydown(){
        var that=this;
        api.post({
            url: 'server/getmydown',
            data: {},
            success: data => {
                that.setData({
                    lists:data.data
                })
            }
        })
    },

    onLoad(options) {
      
    },

 
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getmydown();
    },

    seexieyi1(){
        wx.navigateTo({
          url: '/pages/xieyi/index?id=1',
        })
    },
    seexieyi2(){
        wx.navigateTo({
          url: '/pages/xieyi/index?id=2',
        })
    },
    see1(){
        this.setData({
            xieyi:1
        })
    },
    see0(){
        this.setData({
            xieyi:0
        })
    },
    setshow(){
        var shows=this.data.show;
        console.log(shows);

        if(shows){
            console.log(1);
            this.setData({
                show:false
            })
        }else{
            console.log(0);
            this.setData({
                show:true
            })
        }
    },

    delete(ret){
        var id=ret.currentTarget.dataset.i;
        var that=this;

        wx.showModal({
          title: '删除',
          content: '确定要删除信息？',
          complete: (res) => {
          
            if (res.confirm) {
                api.post({
                    url: 'server/deleteserver',
                    data: {id:id},
                    success: data => {
                        that.getmydown();
                    }
                })
            }
          }
        })


   


    },
    getvalue(ret){
        console.log(ret);
        var val=ret.detail.value;
        var key=ret.currentTarget.dataset.key;

        var info=this.data.info;
            info[key]=val;
        console.log(info);
        this.setData({
            info:info
        })
       

    },
    xuanzhong(ret){
        console.log(ret);

        var i=ret.currentTarget.dataset.i;
        var lists=this.data.lists;

        var info=lists[i];
        console.log(info);
        
        var pages = getCurrentPages();
        var prevPage = pages[pages.length - 2]; // 获取父页面实例对象

        wx.setStorageSync('did', info.id);

        prevPage.setData({
            dname: info.name,
            did:info.id
        });
        
        wx.navigateBack();

    }

})